<template>
    <div class="edu-page-warp">
        <div class="edu-page-title">{{ $t('message.filterCondition') }}</div>
        <el-card shadow="never" body-style="padding: 24px;">
            <el-form ref="queryForm" :model="queryForm" label-width="80px" class="bg-white pd-12px">
                <el-row :gutter="20">
                    <el-col :span="6">
                        <el-form-item label="年级:" :label-width="formLabelWidth" prop="grade">
                            <el-select v-model="queryForm.grade">
                                <el-option
                                    v-for="item in options.grade"
                                    :key="item.value"
                                    :label="item.label"
                                    :value="item.value"
                                />
                            </el-select>
                        </el-form-item>
                    </el-col>
                    <el-col :span="6">
                        <el-form-item
                            label="培养层次:"
                            :label-width="formLabelWidth"
                            prop="trainingLevel"
                        >
                            <el-select v-model="queryForm.trainingLevel">
                                <el-option
                                    v-for="item in options.trainingLevel"
                                    :key="item.value"
                                    :label="item.label"
                                    :value="item.value"
                                />
                            </el-select>
                        </el-form-item>
                    </el-col>
                    <el-col :span="6">
                        <el-form-item
                            label="培养类别:"
                            :label-width="formLabelWidth"
                            prop="studentCategory"
                        >
                            <el-select v-model="queryForm.studentCategory">
                                <el-option
                                    v-for="item in options.studentCategory"
                                    :key="item.value"
                                    :label="item.label"
                                    :value="item.value"
                                />
                            </el-select>
                        </el-form-item>
                    </el-col>
                    <el-col :span="6">
                        <el-form-item label="学院:" :label-width="formLabelWidth" prop="faculty">
                            <el-select
                                v-model="queryForm.faculty"
                                filterable
                                @change="changeFaculty"
                            >
                                <el-option
                                    v-for="item in options.faculty"
                                    :key="item.value"
                                    :label="item.label"
                                    :value="item.value"
                                />
                            </el-select>
                        </el-form-item>
                    </el-col>
                </el-row>
                <el-row :gutter="20">
                    <el-col :span="6">
                        <el-form-item label="专业:" :label-width="formLabelWidth" prop="profession">
                            <el-select v-model="queryForm.profession" filterable>
                                <el-option
                                    v-for="item in options.profession"
                                    :key="item.value"
                                    :label="item.label"
                                    :value="item.value"
                                />
                            </el-select>
                        </el-form-item>
                    </el-col>
                    <el-col :span="12">
                        <div class="empty-box"/>
                    </el-col>
                    <el-col :span="6">
                        <el-form-item class="float-right">
                            <el-button @click="reset">{{ $t('message.reset') }}</el-button>
                            <el-button type="primary" @click="onSubmit">{{ $t('message.filter') }}</el-button>
                        </el-form-item>
                    </el-col>
                </el-row>
            </el-form>
        </el-card>
        <div class="edu-page-title mg-top">应缴费学生名单</div>
        <el-card shadow="never" body-style="padding: 24px;">
            <el-row class="border-bottom" style="height:56px;">
                <el-col :span="4">
                    <el-input
                        v-model="queryForm.keyWord"
                        placeholder="学号或姓名搜索"
                        prefix-icon="el-icon-search"
                        @keyup.enter.native="onSubmit"
                        @blur="onSubmit"
                    />
                </el-col>
                <el-col :span="8">
                    <div class="empty-box"/>
                </el-col>
                <el-col :span="12">
                    <div class="float-right">
                        <el-button plain @click="deleteItems()">删除</el-button>
                        <el-button plain @click="downloadTemplate()">导入模板下载</el-button>
                        <el-button plain @click="batchImport()">导入</el-button>
                        <el-button plain @click="exportFile()">{{ $t('message.export') }}</el-button>
                        <el-button type="primary" @click="addItem()">新增</el-button>
                    </div>
                </el-col>
            </el-row>
            <el-table
                :data="students"
                size="mini"
                ref="studentsTable"
                @selection-change="handlerSelectionChange"
            >
                <el-table-column type="selection" width="55" stripe/>
                <el-table-column prop="studentId" label="学号" width="80"/>
                <el-table-column label="姓名" width="100">
                    <template slot-scope="scope">{{ scope.row.name }}</template>
                </el-table-column>
                <el-table-column label="年级" width="100">
                    <template slot-scope="scope">{{ scope.row.grade }}</template>
                </el-table-column>
                <el-table-column label="学院">
                    <template slot-scope="scope">{{ scope.row.facultyI18n }}</template>
                </el-table-column>
                <el-table-column label="专业">
                    <template slot-scope="scope">{{ scope.row.professionI18n }}</template>
                </el-table-column>
                <el-table-column label="培养层次">
                    <template slot-scope="scope">{{ scope.row.trainingLevelI18n }}</template>
                </el-table-column>
                <el-table-column label="培养类别">
                    <template slot-scope="scope">{{ scope.row.studentCategoryI18n }}</template>
                </el-table-column>
                <el-table-column label="总应缴费金额">
                    <template slot-scope="scope">{{ scope.row.sum }}</template>
                </el-table-column>
                <el-table-column label="操作" width="90">
                    <template slot-scope="scope">
                        <el-button type="text" size="mini" @click="editItem(scope.row)">编辑</el-button>
                        <el-button type="text" size="mini" @click="deleteItem(scope.row)">删除</el-button>
                        <!-- <el-button type="text" @click="editTask(scope.row)" size="mini">编辑</el-button> -->
                    </template>
                </el-table-column>
            </el-table>

            <div class="edu-pagination">
                <div class="float-right">
                    <el-pagination
                        :current-page="queryForm.pageNum_"
                        :page-sizes="[20,50,100,500,1000]"
                        :page-size="queryForm.pageSize_"
                        :total="total"
                        layout="total, sizes, prev, pager, next, jumper"
                        style="float: right;margin:10px 60px 0 0;"
                        @size-change="handleSizeChange"
                        @current-change="handleCurrentChange"
                    />
                </div>
            </div>
        </el-card>
        <!--添加应缴费弹窗-->
        <el-dialog
            :title.sync="dialogConfig.dialogTitle"
            :visible.sync="dialogConfig.showDialog"
            :before-close="handleClose"
            top="5vh"
            width="60%"
        >
            <el-form
                :model="dialogConfig.form"
                :inline="true"
                :rules="dialogConfig.rules"
                ref="addItemForm"
            >
                <div class="edu-page-title">学生信息</div>
                <el-row :gutter="20">
                    <el-col :span="6">
                        <el-form-item label="学号:" :label-width="dialogConfig.studentInfoLabelWidth">
                            <el-input
                                v-model="dialogConfig.current.studentId"
                                placeholder="请输入"
                                :disabled="dialogConfig.flagEdit"
                                @keyup.enter.native="getUserInfoById"
                                @blur="getUserInfoById"
                            />
                        </el-form-item>
                    </el-col>
                    <el-col :span="6">
                        <el-form-item label="姓名:" :label-width="dialogConfig.studentInfoLabelWidth">
                            <el-input v-model="dialogConfig.current.name" :disabled="true"/>
                        </el-form-item>
                    </el-col>
                    <el-col :span="6">
                        <el-form-item
                            label="培养层次:"
                            :label-width="dialogConfig.studentInfoLabelWidth"
                        >
                            <el-input
                                v-model="dialogConfig.current.trainingLevelI18n"
                                :disabled="true"
                            />
                        </el-form-item>
                    </el-col>
                    <el-col :span="6">
                        <el-form-item
                            label="培养类别:"
                            :label-width="dialogConfig.studentInfoLabelWidth"
                        >
                            <el-input
                                v-model="dialogConfig.current.studentCategoryI18n"
                                :disabled="true"
                            />
                        </el-form-item>
                    </el-col>
                </el-row>
                <el-row :gutter="20">
                    <el-col :span="6">
                        <el-form-item label="年级:" :label-width="dialogConfig.studentInfoLabelWidth">
                            <el-input v-model="dialogConfig.current.grade" :disabled="true"/>
                        </el-form-item>
                    </el-col>
                    <el-col :span="6">
                        <el-form-item label="学院:" :label-width="dialogConfig.studentInfoLabelWidth">
                            <el-input v-model="dialogConfig.current.facultyI18n" :disabled="true"/>
                        </el-form-item>
                    </el-col>
                    <el-col :span="6">
                        <el-form-item label="专业:" :label-width="dialogConfig.studentInfoLabelWidth">
                            <el-input
                                v-model="dialogConfig.current.professionI18n"
                                :disabled="true"
                            />
                        </el-form-item>
                    </el-col>
                    <el-col :span="6">
                        <el-form-item label="学制:" :label-width="dialogConfig.studentInfoLabelWidth">
                            <el-input v-model="dialogConfig.current.profession" :disabled="true"/>
                        </el-form-item>
                    </el-col>
                </el-row>
                <div class="edu-page-title">学年应缴费信息</div>
                <el-row :gutter="20">
                    <el-col :span="8">
                        <el-form-item
                            label="第一学年第1学期:"
                            :label-width="dialogConfig.formLabelWidth"
                            prop="semester1"
                        >
                            <el-input v-model="dialogConfig.form.semester1" placeholder="请输入"/>
                        </el-form-item>
                    </el-col>
                    <el-col :span="8">
                        <el-form-item
                            label="第一学年第2学期:"
                            :label-width="dialogConfig.formLabelWidth"
                            prop="semester2"
                        >
                            <el-input v-model="dialogConfig.form.semester2" placeholder="请输入"/>
                        </el-form-item>
                    </el-col>
                    <el-col :span="8">
                        <div class="empty-box"/>
                    </el-col>
                </el-row>
                <el-row :gutter="20">
                    <el-col :span="8">
                        <el-form-item
                            label="第二学年第1学期:"
                            :label-width="dialogConfig.formLabelWidth"
                            prop="semester3"
                        >
                            <el-input v-model="dialogConfig.form.semester3" placeholder="请输入"/>
                        </el-form-item>
                    </el-col>
                    <el-col :span="8">
                        <el-form-item
                            label="第二学年第2学期:"
                            :label-width="dialogConfig.formLabelWidth"
                            prop="semester4"
                        >
                            <el-input v-model="dialogConfig.form.semester4" placeholder="请输入"/>
                        </el-form-item>
                    </el-col>
                    <el-col :span="8">
                        <div class="empty-box"/>
                    </el-col>
                </el-row>
                <el-row :gutter="20">
                    <el-col :span="8">
                        <el-form-item
                            label="第三学年第1学期:"
                            :label-width="dialogConfig.formLabelWidth"
                            prop="semester5"
                        >
                            <el-input v-model="dialogConfig.form.semester5" placeholder="请输入"/>
                        </el-form-item>
                    </el-col>
                    <el-col :span="8">
                        <el-form-item
                            label="第三学年第2学期:"
                            :label-width="dialogConfig.formLabelWidth"
                            prop="semester6"
                        >
                            <el-input v-model="dialogConfig.form.semester6" placeholder="请输入"/>
                        </el-form-item>
                    </el-col>
                    <el-col :span="8">
                        <div class="empty-box"/>
                    </el-col>
                </el-row>
                <el-row :gutter="20">
                    <el-col :span="8">
                        <el-form-item
                            label="第四学年第1学期:"
                            :label-width="dialogConfig.formLabelWidth"
                            prop="semester7"
                        >
                            <el-input v-model="dialogConfig.form.semester7" placeholder="请输入"/>
                        </el-form-item>
                    </el-col>
                    <el-col :span="8">
                        <el-form-item
                            label="第四学年第2学期:"
                            :label-width="dialogConfig.formLabelWidth"
                            prop="semester8"
                        >
                            <el-input v-model="dialogConfig.form.semester8" placeholder="请输入"/>
                        </el-form-item>
                    </el-col>
                    <el-col :span="8">
                        <div class="empty-box"/>
                    </el-col>
                </el-row>
                <el-row :gutter="20">
                    <el-col :span="8">
                        <el-form-item
                            label="第五学年五第1学期:"
                            :label-width="dialogConfig.formLabelWidth"
                            prop="semester9"
                        >
                            <el-input v-model="dialogConfig.form.semester9" placeholder="请输入"/>
                        </el-form-item>
                    </el-col>
                    <el-col :span="8">
                        <el-form-item
                            label="第五学年第2学期:"
                            :label-width="dialogConfig.formLabelWidth"
                            prop="semester10"
                        >
                            <el-input v-model="dialogConfig.form.semester10" placeholder="请输入"/>
                        </el-form-item>
                    </el-col>
                    <el-col :span="8">
                        <div class="empty-box"/>
                    </el-col>
                </el-row>
                <el-row :gutter="20">
                    <el-col :span="8">
                        <el-form-item
                            label="第六学年第1学期:"
                            :label-width="dialogConfig.formLabelWidth"
                            prop="semester11"
                        >
                            <el-input v-model="dialogConfig.form.semester11" placeholder="请输入"/>
                        </el-form-item>
                    </el-col>
                    <el-col :span="8">
                        <el-form-item
                            label="第六学年第2学期:"
                            :label-width="dialogConfig.formLabelWidth"
                            prop="semester12"
                        >
                            <el-input v-model="dialogConfig.form.semester12" placeholder="请输入"/>
                        </el-form-item>
                    </el-col>
                    <el-col :span="8">
                        <div class="empty-box"/>
                    </el-col>
                </el-row>
                <el-row :gutter="20">
                    <el-col :span="16">
                        <el-form-item label="备注：" :label-width="dialogConfig.formLabelWidth">
                            <el-input
                                style="width: calc(300% - 100px);"
                                v-model="dialogConfig.form.comments"
                                placeholder="请输入"
                                type="textarea"
                            />
                        </el-form-item>
                    </el-col>
                    <el-col :span="8">
                        <div class="empty-box"/>
                    </el-col>
                </el-row>
                <el-row :gutter="20">
                    <el-col :span="8">
                        <el-form-item label="总应缴费用：" :label-width="dialogConfig.formLabelWidth">
                            <el-input v-model="sum" :disabled="true"/>
                        </el-form-item>
                    </el-col>
                    <el-col :span="16">
                        <div class="empty-box"/>
                    </el-col>
                </el-row>
            </el-form>
            <span slot="footer" class="dialog-footer">
                <el-button @click="dialogConfig.showDialog = false">取 消</el-button>
                <el-button
                    type="primary"
                    @click="handlerAddItem"
                    :disabled="dialogConfig.falgCanNotSubmit"
                >确 定</el-button>
            </span>
        </el-dialog>
        <!--删除操作-->
        <delete-dialog
            :modal-title="deleteDialogConfig.dialogTitle"
            title="确认删除以下信息"
            :show-dialog="deleteDialogConfig.showDialog"
            :data="deleteDialogConfig.students"
            :columns="deleteDialogConfig.columns"
            :ok-call-back="handlerDeleteItems"
            :handle-close="handlerDeleteDialogClose"
        />
        <!--批量导入弹窗-->
        <el-dialog
            :title.sync="batchImportDialog.dialogTitle"
            :visible.sync="batchImportDialog.showDialog"
            width="30%"
        >
            <el-upload
                action="/api/studentservice/paymentlist/importPaymentList"
                class="upload-demo"
                ref="upload"
                :on-success="handlerSuccess"
                :on-error="handlerError"
                accept="xlsx"
                :auto-upload="true"
            >
                <el-button slot="trigger" size="small" type="primary">选取文件</el-button>
            </el-upload>
            <span slot="footer" class="dialog-footer">
                <el-button @click="batchImportDialog.showDialog = false">关闭</el-button>
            </span>
        </el-dialog>
    </div>
</template>
<script>
import * as API from "common/src/api/arrearsStudentList";
import { queryDic } from "common/src/api/dictionary";
import utils from "common/src/utils/utils";
import deleteDialog from "./DeleteItems";
export default {
    name: "ArrearsStudentList",
    components: { deleteDialog },
    data() {
        const getGrade = (function() {
            const now = new Date().getFullYear();
            const years = [];
            for (let i = 0; i < 6; i++) {
                years.push({
                    label: now - i,
                    value: now - i
                });
            }
            return years;
        })();
        return {
            loading: false,
            formLabelWidth: "100px",
            queryForm: {
                grade: "",
                faculty: "",
                trainingLevel: "",
                profession: "",
                studentCategory: "",
                keyWord: "",
                pageNum_: 1,
                pageSize_: 20
            },
            options: {
                trainingLevel: [],
                grade: getGrade,
                faculty: [],
                profession: [],
                studentCategory: []
            },
            students: [],
            total: 0,
            selectedItems: [],
            dialogConfig: {
                dialogTitle: "应缴费金额",
                showDialog: false,
                flagEdit: false,
                tipText: "",
                falgCanNotSubmit: true,
                form: {},
                formLabelWidth: "120px",
                studentInfoLabelWidth: "80px",
                current: {},
                rules: {
                    semester1: [
                        {
                            validator: this.checkInt,
                            trigger: "blur"
                        }
                    ],
                    semester2: [
                        {
                            validator: this.checkInt,
                            trigger: "blur"
                        }
                    ],
                    semester3: [
                        {
                            validator: this.checkInt,
                            trigger: "blur"
                        }
                    ],
                    semester4: [
                        {
                            validator: this.checkInt,
                            trigger: "blur"
                        }
                    ],
                    semester5: [
                        {
                            validator: this.checkInt,
                            trigger: "blur"
                        }
                    ],
                    semester6: [
                        {
                            validator: this.checkInt,
                            trigger: "blur"
                        }
                    ],
                    semester7: [
                        {
                            validator: this.checkInt,
                            trigger: "blur"
                        }
                    ],
                    semester8: [
                        {
                            validator: this.checkInt,
                            trigger: "blur"
                        }
                    ],
                    semester9: [
                        {
                            validator: this.checkInt,
                            trigger: "blur"
                        }
                    ],
                    semester10: [
                        {
                            validator: this.checkInt,
                            trigger: "blur"
                        }
                    ],
                    semester11: [
                        {
                            validator: this.checkInt,
                            trigger: "blur"
                        }
                    ],
                    semester12: [
                        {
                            validator: this.checkInt,
                            trigger: "blur"
                        }
                    ]
                }
            },
            deleteDialogConfig: {
                dialogTitle: "删除",
                showDialog: false,
                students: [],
                columns: [
                    { label: "学号", key: "studentId" },
                    { label: "姓名", key: "name" },
                    { label: "年级", key: "grade" },
                    { label: "学院", key: "facultyI18n" },
                    { label: "专业", key: "professionI18n" },
                    { label: "培养层次", key: "trainingLevelI18n" },
                    { label: "培养类别", key: "studentCategoryI18n" },
                    { label: "总应缴费金额", key: "sum" }
                ]
            },
            batchImportDialog: {
                dialogTitle: "批量上传",
                showDialog: false
            }
        };
    },
    mounted() {
        this.initOptions();
    },
    methods: {
        handlerSuccess(response, file, fileList) {
            let responseCode = response.code;
            if (responseCode === 200) {
                this.$message({
                    message: "上传成功！",
                    type: "success"
                });
                this.onSubmit();
            } else {
                this.$message({
                    message: "文件列名错误或文件为空！",
                    type: "error"
                });
            }
            this.batchImportDialog.showDialog = false;
        },
        handlerError(rresponse, file, fileList) {
            this.$message({
                message: "上传失败！",
                type: "error"
            });
            this.batchImportDialog.showDialog = false;
        },
        checkInt(rule, value, callback) {
            if (!/^[1-9]\d*(\.\d+)?$|^0(\.\d*[1-9]\d*)?$/.test(value)) {
                return callback(new Error("请输入数字"));
            }
            return callback();
        },
        initOptions() {
            const data = {
                lang: this.$store.getters.language || "cn",
                type: "allChild",
                keys: ["X_PYCC", "X_YX", "X_PYLB"]
            };
            queryDic(data).then(res => {
                if (res.code === 200) {
                    this.fillSelect(res.data);
                    this.onSubmit();
                }
            });
        },
        changeFaculty(val) {
            this.options["profession"] = [];
            const data = {
                lang: this.$store.getters.language || "cn",
                type: "allChild",
                keys: ["G_ZY"],
                filter: {
                    prefix: [val],
                    specilaCode: "XY2ZY"
                }
            };
            queryDic(data).then(res => {
                if (res.code === 200) this._fill("profession", res.data.G_ZY);
            });
        },
        fillSelect(data) {
            let { X_PYCC, X_YX, X_PYLB } = data;
            this._fill("trainingLevel", X_PYCC);
            this._fill("faculty", X_YX);
            this._fill("studentCategory", X_PYLB);
            // this._fill("profession", data.G_ZY);
        },
        _fill(type, data) {
            for (const key in data) {
                this.options[type].push({
                    value: key,
                    label: data[key]
                });
            }
        },
        onSubmit() {
            this.loading = true;
            API.getArrearsStudentList(this.queryForm)
                .then(response => {
                    if (response.code === 200) {
                        this.students = response.data.list;
                        this.total = response.data.total_;
                    } else throw response.code;
                })
                .finally(() => (this.loading = false));
        },
        addItem() {
            this.dialogConfig.current = {};
            this.dialogConfig.form = {};
            this.dialogConfig.flagEdit = false;
            this.dialogConfig.showDialog = true;
            this.dialogConfig.falgCanNotSubmit = true;
        },
        editItem(item) {
            this.dialogConfig.flagEdit = true;
            this.dialogConfig.showDialog = true;
            this.dialogConfig.falgCanNotSubmit = false;
            this.dialogConfig.current = item;
            let {
                semester1,
                semester2,
                semester3,
                semester4,
                semester5,
                semester6,
                semester7,
                semester8,
                semester9,
                semester10,
                semester11,
                semester12,
                sum,
                studentId,
                comments
            } = item;
            this.dialogConfig.form = {
                semester1,
                semester2,
                semester3,
                semester4,
                semester5,
                semester6,
                semester7,
                semester8,
                semester9,
                semester10,
                semester11,
                semester12,
                sum,
                studentId,
                comments
            };
        },
        getUserInfoById() {
            API.getArrearsStudentDetail({
                studentId: this.dialogConfig.current.studentId
            }).then(
                response => {
                    let { code, data } = response;
                    if (code === 200) {
                        // 添加的情况
                        if (!this.dialogConfig.flagEdit) {
                            //如果发现学生已经设置过缴费
                            if (data) {
                                if (data.sum) {
                                    this.$message({
                                        message:
                                            "该学生已设置完成缴费金额，请在编辑中修改!",
                                        type: "error"
                                    });
                                    this.dialogConfig.falgCanNotSubmit = true;
                                } else {
                                    // 如果学生没设置缴费

                                    this.dialogConfig.falgCanNotSubmit = false;
                                }
                                this.dialogConfig.current = data;
                            } else {
                                this.$message({
                                    message: `不存在学号为${
                                        this.dialogConfig.current.studentId
                                    }的学生`,
                                    type: "error"
                                });
                            }
                        }
                    }
                },
                xhr => {
                    this.dialogConfig.falgCanNotSubmit = true;
                }
            );
        },
        handlerAddItem() {
            // 验证输入是否都正确
            this.$refs["addItemForm"].validate(valid => {
                if (valid) {
                    // 编辑时提交
                    if (this.dialogConfig.flagEdit) {
                        this.dialogConfig.form.sum = this.sum;
                        API.editArrearsStudent(this.dialogConfig.form)
                            .then(
                                response => {
                                    if (response.code === 200) {
                                        this.$message({
                                            message: "修改成功",
                                            type: "success"
                                        });
                                        this.onSubmit();
                                    }
                                },
                                xhr => {}
                            )
                            .finally(
                                () => (this.dialogConfig.showDialog = false)
                            );
                    } else {
                        // 添加时提交
                        API.getArrearsStudent({
                            ...this.dialogConfig.form,
                            sum: this.sum,
                            studentId: this.dialogConfig.current.studentId
                        })
                            .then(
                                response => {
                                    if (response.code === 200) {
                                        this.$message({
                                            message: "添加成功",
                                            type: "success"
                                        });
                                        this.onSubmit();
                                    }
                                },
                                xhr => {}
                            )
                            .finally(() => {
                                this.dialogConfig.showDialog = false;
                            });
                    }
                }
            });
        },
        handleClose(done) {
            this.dialogConfig.current = {};
            this.dialogConfig.form = {};
            done();
        },
        // 删除选中的项目
        deleteItems() {
            let { selectedItems } = this;
            if (selectedItems.length === 0) {
                return this.$message({
                    message: "请选中至少一条数据",
                    type: "error"
                });
            }
            this.deleteDialogConfig.students = selectedItems;
            this.deleteDialogConfig.showDialog = true;
        },
        deleteItem(row) {
            this.deleteDialogConfig.students = [row];
            this.deleteDialogConfig.showDialog = true;
        },
        handlerDeleteDialogClose() {
            this.deleteDialogConfig.showDialog = false;
        },
        handlerDeleteItems() {
            let params = this.deleteDialogConfig.students.map(
                item => item.studentId
            );
            API.deleteArrearsStudent(params)
                .then(
                    response => {
                        if (response.code === 200) {
                            this.$message({
                                message: "删除成功！",
                                type: "success"
                            });
                            this.onSubmit();
                        }
                    },
                    xhr => {}
                )
                .finally(() => {
                    this.deleteDialogConfig.showDialog = false;
                });
        },
        handlerDeleteDialogCurrentChange(val) {
            this.deleteDialogConfig.pagination.currentPage = val;
        },
        handleCurrentChange(val) {
            this.queryForm.pageNum_ = val;
            this.onSubmit();
        },
        handleSizeChange(val) {
            this.queryForm.pageSize_ = val;
            this.onSubmit();
        },
        handlerSelectionChange(val) {
            this.selectedItems = val;
        },
        reset() {
            this.queryForm.trainingLevel = "";
            this.queryForm.grade = "";
            this.queryForm.faculty = "";
            this.queryForm.profession = "";
            this.queryForm.studentCategory = "";
            this.queryForm.keyWord = "";
            this.queryForm.pageNum_ = 1;
            this.queryForm.pageSize_ = 20;
            this.onSubmit();
        },
        downloadTemplate() {
            let columns = [
                [
                    "学号",
                    "总应交费用",
                    "第1学年第一学期",
                    "第1学年第二学期",
                    "第2学年第一学期",
                    "第2学年第二学期",
                    "第3学年第一学期",
                    "第3学年第二学期",
                    "第4学年第一学期",
                    "第4学年第二学期",
                    "第5学年第一学期",
                    "第5学年第二学期",
                    "第6学年第一学期",
                    "第6学年第二学期"
                ]
            ];
            utils.exportAsXlsx(columns, "应缴费名单导入模板.xlsx");
        },
        batchImport() {
            this.batchImportDialog.showDialog = true;
        },
        // uploadFile() {
        //     let file = this.$refs.upload.fileList[0]
        //     if (!file) {
        //         this.$message({
        //             type: 'error',
        //             message: '没选择任何文件！',
        //         })
        //         return
        //     }
        //     if (!/.+\.xlsx$/.test(file.name)) {
        //         this.$message({
        //             type: 'error',
        //             message: '请选择xlsx结尾的文件！',
        //         })
        //         return
        //     }
        //     this.$refs.upload.submit()
        // },
        exportFile() {
            let params = utils.clone(this.queryForm);
            params.hasOwnProperty("pageNum_") && delete params.pageNum_;
            params.hasOwnProperty("pageSize_") && delete params.pageSize_;
            if (!this.isAllKeyEmpty(params)) {
                return this.$message({
                    type: "error",
                    message: "请选择至少一个条件导出数据！"
                });
            }
            API.exportArrearsStudentList(params);
            //findStuInfoListExport(this.queryForm)
        },
        isAllKeyEmpty(obj = {}) {
            return !!Object.values(obj).join("");
        }
    },
    computed: {
        start() {
            return (this.deleteDialogConfig.pagination.currentPage - 1) * 10;
        },
        end() {
            return Math.min(
                this.deleteDialogConfig.pagination.currentPage * 10,
                this.deleteDialogConfig.students.length
            );
        },
        sum() {
            let keys = Object.keys(this.dialogConfig.form).filter(
                item => item.indexOf("semester") === 0
            );
            return keys.reduce((prev, curr) => {
                if (
                    /^[1-9]\d*(\.\d+)?$|^0(\.\d*[1-9]\d*)?$/.test(
                        this.dialogConfig.form[curr]
                    )
                ) {
                    prev += +this.dialogConfig.form[curr] || 0;
                }
                return prev;
            }, 0);
        }
    }
};
</script>
<style>
</style>
